<?php

namespace App\Http\Controllers\Admin;

use App\Dictionary;
use App\Repository\LostRepository;
use App\Repository\MessageRepository;
use App\Repository\RepairRepository;
use App\Repository\TemplateRepository;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Repository\UserRepository;
class HomeController extends Controller
{
    /**
     * @var UserRepository
     */
    private $user;
    /**
     * @var MessageRepository
     */
    private $message;
    /**
     * @var RepairRepository
     */
    private $repair;
    /**
     * @var LostRepository
     */
    private $lost;
    /**
     * @var TemplateRepository
     */
    private $template;

    /**
     * HomeController constructor.
     * @param UserRepository $user
     * @param MessageRepository $message
     * @param RepairRepository $repair
     * @param LostRepository $lost
     * @param TemplateRepository $template
     */
    public function __construct(
        UserRepository $user,
        MessageRepository $message,
        RepairRepository $repair,
        LostRepository $lost,
        TemplateRepository $template
    )
    {

        $this->user = $user;
        $this->message = $message;
        $this->repair = $repair;
        $this->lost = $lost;
        $this->template = $template;
    }

    public function index()
    {
        $userCount = $this->user->getUserCount();
        $bindCount = $this->user->getBindCount();

        $heatMessages = $this->message->getHeatMessage();

        $repairCount = $this->repair->getCount();

        $repairSolveCount = $this->repair->getCountByStatus(2);
        $repairUnSolveCount = $this->repair->getCountByStatus(0);

        $lostCount = $this->lost->getCount();
        $lostFinishCount = $this->lost->getFinishCount();

        $lostPublishCount = $this->template->search(['templateId' => config('wechat.template.lost_publish')])->total();

        return view('home', compact(
            'userCount',
            'bindCount',
            'heatMessages',
            'repairCount',
            'repairSolveCount',
            'repairUnSolveCount',
            'lostCount',
            'lostFinishCount',
            'lostPublishCount'
        ));
    }
    

}
